#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QPushButton>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    this->setWindowTitle("这是窗口标题");
    // 设置图标 qrc
    // QIcon icon("C:/Users/zhouzifan/Pictures/vsc.jpg");
    QIcon icon(":/apple.jpg");
    this->setWindowIcon(icon);

    // 此处直接针对 widget对象 来使用 geometry 和 framegeometry，观察区别
    QRect rect1 = this->geometry();
    QRect rect2 = this->frameGeometry();
    qDebug() << rect1;
    qDebug() << rect2;
    // 此时还没有加入到window frame 中

    QPushButton* button = new QPushButton(this);
    button->setText("按钮");
    button->move(100, 100);
    connect(button, &QPushButton::clicked, this, &Widget::handle);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::handle()
{
    QRect rect1 = this->geometry();
    QRect rect2 = this->frameGeometry();
    qDebug() << rect1;
    qDebug() << rect2;
}

// 不透明度
void Widget::on_pushButton_add_clicked()
{
    // 注意浮点数的问题
    float opacity = this->windowOpacity();
    if(opacity >= 1.0) return ;         // 虽然可以不加 但是良好的编码规范

    qDebug() << opacity;
    opacity += 0.1;
    this->setWindowOpacity(opacity);
}

void Widget::on_pushButton_sub_clicked()
{
    float opacity = this->windowOpacity();
    if(opacity <= 0) return ;

    qDebug() << opacity;
    opacity -= 0.1;
    this->setWindowOpacity(opacity);
}
